﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace iStudio.Module.Equalizer
{
    internal class EqualizerCache
    {
        private readonly List<List<double>> _cache;
        private readonly List<float> _raw; 

        /// <summary>
        /// Instancise cache of size
        /// </summary>
        /// <param name="size">Filter count</param>
        public EqualizerCache (int size)
        {
            _cache = new List<List<double>> ();
            _raw = new List<float> ();

            for (int i = 0; i < size; i++)
            {
                _cache.Add (new List<double> ());
            }
        }


        /// <summary>
        /// Returns cache of the
        /// </summary>
        /// <param name="i"></param>
        /// <returns></returns>
        public List<double> GetCache (int i)
        {
            return _cache[i];
        }

        public void SetCache (int index, double[] values, int offset, int count)
        {
            _cache[index].Clear();

            for (int i = offset; i < (offset + count); i++)
            {
                _cache[index].Add(values[i]);
            }
        }

        public void SetCache(int i, IEnumerable<double> values)
        {
            _cache[i].Clear();
            _cache[i].AddRange(values);
        }

        public void SetRawCache (float[] values, int offset, int count)
        {
            _raw.Clear ();
            
            for (int i = offset; i < (offset + count); i++)
            {
                _raw.Add (values[i]);
            }
        }
        public void SetRawCache(IEnumerable<float> values)
        {
            _raw.Clear();
            _raw.AddRange(values);
        }


        public List<float> GetRawCache()
        {
            return _raw;
        }
    }
}
